package com.komorebishao.code;

import java.util.Arrays;

public class Code283 {

    public static void main(String... args) {
        int[] intput = new int[] {0, 1, 13, 0, 8};
        moveZeros2(intput);
        System.out.println(Arrays.toString(intput));
    }

    public static void moveZeros(int[] nums) {
        if (nums == null) {
            return;
        }
        int j = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] != 0) {
                nums[j++] = nums[i];
            }
        }
        for (int i = j; i < nums.length; i++) {
            nums[i] = 0;
        }
    }

    public static void moveZeros2(int[] nums) {
        if (nums == null || nums.length == 0) {
            return;
        }
        int j = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] != 0) {
                int temp = nums[i];
                nums[i] = nums[j];
                nums[j++] = temp;
            }
        }
    }
}
